package com.geologyoa.persist;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.geologyoa.commons.JdbcUtil;
import com.geologyoa.domain.Dwzz01;

public class Dwzz01DaoImpl implements Dwzz01Dao {
	Connection conn = null;
	PreparedStatement ps = null;
	ResultSet rs = null;
	public Boolean AddDwzz(Dwzz01 dwzz01) {
		Boolean flag =false;
		   conn=JdbcUtil.getConnection();
		   String sql = "";
		  sql = "insert into dwzz01 values(oa_seq.nextval,?,?,?,?," +
		  		"?,?,?,?,?," +
		  		"?)";
			try {
				ps = conn.prepareStatement(sql);
				ps.setString(1, dwzz01.getDwzz0102());
				ps.setString(2, dwzz01.getDwzz0103());
				ps.setString(3, dwzz01.getDwzz0104());
				ps.setString(4, dwzz01.getDwzz0105());
				ps.setString(5, dwzz01.getDwzz0106());
				ps.setString(6, dwzz01.getDwzz0107());
				ps.setString(7, dwzz01.getDwzz0108());
				ps.setString(8, dwzz01.getDwzz0109());
				ps.setString(9, dwzz01.getDwzz0118());
				ps.setString(10, dwzz01.getDwzz0119());
				int number=ps.executeUpdate();
				if(number>0)
				{
					flag=true;
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			} finally
			{
				JdbcUtil.closeAll(ps,conn);
			}
			return flag;
	}
	public List<Dwzz01> SerachDwzz(String DWZZ0102,String DWZZ0103,String DWZZ0104,String DWZZ0105,String DWZZ0106,String DWZZ0109) {
		Dwzz01 dwzz01=null;
		List<Dwzz01> dwzz01List=new ArrayList<Dwzz01>();
		   conn=JdbcUtil.getConnection();
		   StringBuffer sql = new StringBuffer();	
		   sql.append("select * from dwqk01,dwzz01 where dwqk0101=dwzz0102 ");
		   if(DWZZ0102!=null&&!DWZZ0102.equals("")&&!DWZZ0102.equals("null")){
			   sql.append(" and dwzz0102 like'%"+DWZZ0102+"%'"); 
		   }
		   	if(DWZZ0103!=null&&!DWZZ0103.equals("")&&!DWZZ0103.equals("null")){
		    	  sql.append(" and DWZZ0103 like'%"+DWZZ0103+"%'");  
		      }
		    	  
		      if(DWZZ0104!=null&&!DWZZ0104.equals("")&&!DWZZ0104.equals("null")){
		    	  sql.append(" and DWZZ0104 like'%"+DWZZ0104+"%'");  
		      }
		      if(DWZZ0105!=null&&!DWZZ0105.equals("")&&!DWZZ0105.equals("null")){
		    	  sql.append(" and DWZZ0105 like'%"+DWZZ0105+"%'");  
		      }
		      if(DWZZ0106!=null&&!DWZZ0106.equals("")&&!DWZZ0106.equals("null")){
		    	  sql.append(" and DWZZ0106 like'%"+DWZZ0106+"%'");  
		      }
		      if(DWZZ0109!=null&&!DWZZ0109.equals("")&&!DWZZ0109.equals("null")){
		    	  sql.append(" and DWZZ0109 ='"+DWZZ0109+"'"); 
		      }
		      /*if(DWZZ0103.equals("")==false)
		      {
		    	  sql.append(" and DWZZ0103 like'%"+DWZZ0103+"%'");  
		      }
		    	  
		      if(DWZZ0104.equals("")==false)
		      {
		    	  sql.append(" and DWZZ0104 like'%"+DWZZ0104+"%'");  
		      }
		      if(DWZZ0105.equals("")==false)
		      {
		    	  sql.append(" and DWZZ0105 like'%"+DWZZ0105+"%'");  
		      }
		      if(DWZZ0106.equals("")==false)
		      {
		    	  sql.append(" and DWZZ0106 like'%"+DWZZ0106+"%'");  
		      }*/
			try {
				ps = conn.prepareStatement(sql.toString());
				rs=ps.executeQuery();
				while(rs.next())
				{
					dwzz01=new Dwzz01();
					//System.out.println(rs.getString("dwqk0102"));
					dwzz01.setDwzz0101(Integer.parseInt(rs.getString("dwzz0101")));
					dwzz01.setDwzz0102(rs.getString("dwzz0102"));//单位id
					dwzz01.setDwzz0103(rs.getString("dwqk0103"));
					dwzz01.setDwzz0104(rs.getString("dwzz0104"));
					dwzz01.setDwzz0105(rs.getString("dwzz0105"));
					dwzz01.setDwzz0106(rs.getString("dwzz0106"));
					dwzz01.setDwzz0107(rs.getString("dwzz0107")==null?"":rs.getString("dwzz0107"));
					dwzz01.setDwzz0108(rs.getString("dwzz0108")==null?"":rs.getString("dwzz0108"));
					dwzz01.setDwzz0109(rs.getString("dwzz0109"));
					dwzz01.setDwzz0118(rs.getString("dwzz0118"));
					dwzz01.setDwzz0119(rs.getString("dwzz0119"));
					dwzz01.setDwzz0120(rs.getString("dwqk0102"));//单位统一编号
					dwzz01List.add(dwzz01);
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			} finally
			{
				JdbcUtil.closeAll(ps,conn);
			}
			return dwzz01List;
	}
	public Boolean DelDwzz(String DWZZ0101) {
		Boolean flag =false;
		   conn=JdbcUtil.getConnection();
		   String sql = "";
		   sql = "delete from dwzz01  where DWZZ0101=?";
			try {
				ps = conn.prepareStatement(sql);
				ps.setString(1, DWZZ0101);
				int number=ps.executeUpdate();
				if(number>0)
				{
					flag=true;
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			} finally
			{
				JdbcUtil.closeAll(ps,conn);
			}
			return flag;
	}
	public Boolean UpdateDwzz(Dwzz01 dwzz01) {
		 Boolean flag =false;
		   conn=JdbcUtil.getConnection();
		   String sql = "";
		   sql = "update dwzz01 set dwzz0102=?,dwzz0103 =?,dwzz0104=?,dwzz0105=?,dwzz0106=?,dwzz0107=?,dwzz0108=?,dwzz0109=?,dwzz0118=?,dwzz0119=? where dwzz0101=?";
			try {
				ps = conn.prepareStatement(sql);
				ps.setString(1, dwzz01.getDwzz0102());
				ps.setString(2, dwzz01.getDwzz0103());
				ps.setString(3, dwzz01.getDwzz0104());
				ps.setString(4, dwzz01.getDwzz0105());
				ps.setString(5, dwzz01.getDwzz0106());
				ps.setString(6, dwzz01.getDwzz0107());
				ps.setString(7, dwzz01.getDwzz0108());
				ps.setString(8, dwzz01.getDwzz0109());
				ps.setString(9, dwzz01.getDwzz0118());
				ps.setString(10, dwzz01.getDwzz0119());
				ps.setString(11, dwzz01.getDwzz0101().toString());
				int number=ps.executeUpdate();
				if(number>0)
				{
					flag=true;
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			} finally
			{
				JdbcUtil.closeAll(ps,conn);
			}
			return flag;
	}

}
